﻿namespace Sidvall.Caching
{
	public class CacheManager
	{
		#region Public Members

		public Sidvall.Caching.ICache Cache { get; set; }

		#region Add

		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
		public bool Add(CacheItem item, CacheItemPolicy policy)
		{
			return this.Cache.Add(item, policy);
		}
		public bool Add(string key, object value, string regionName, CacheItemPolicy policy)
		{
			CacheItem item;

			item = new CacheItem()
			{
				Key = key,
				Value = value,
				RegionName = regionName,
			};
			return Add(item, policy);
		}
		public bool Add(string key, object value, string regionName, System.TimeSpan slidingExpiration)
		{
			CacheItemPolicy policy;

			policy = new CacheItemPolicy()
			{
				SlidingExpiration = slidingExpiration,
			};
			return Add(key, value, regionName, policy);
		}
		public bool Add(string key, object value, string regionName, System.DateTimeOffset absoluteExpiration)
		{
			CacheItemPolicy policy;

			policy = new CacheItemPolicy()
			{
				AbsoluteExpiration = absoluteExpiration,
			};
			return Add(key, value, regionName, policy);
		}

		#endregion
		#region AddOrGetExisting

		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
		public CacheItem AddOrGetExisting(CacheItem item, CacheItemPolicy policy)
		{
			return this.Cache.AddOrGetExisting(item, policy);
		}
		public CacheItem AddOrGetExisting(string key, object value, string regionName, CacheItemPolicy policy)
		{
			CacheItem item;

			item = new CacheItem()
			{
				Key = key,
				Value = value,
				RegionName = regionName,
			};
			return AddOrGetExisting(item, policy);
		}
		public CacheItem AddOrGetExisting(string key, object value, string regionName, System.TimeSpan slidingExpiration)
		{
			CacheItemPolicy policy;

			policy = new CacheItemPolicy()
			{
				SlidingExpiration = slidingExpiration,
			};
			return AddOrGetExisting(key, value, regionName, policy);
		}
		public CacheItem AddOrGetExisting(string key, object value, string regionName, System.DateTimeOffset absoluteExpiration)
		{
			CacheItemPolicy policy;

			policy = new CacheItemPolicy()
			{
				AbsoluteExpiration = absoluteExpiration,
			};
			return AddOrGetExisting(key, value, regionName, policy);
		}

		#endregion
		#region AddOrUpdate

		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
		public void AddOrUpdate(CacheItem item, CacheItemPolicy policy)
		{
			this.Cache.AddOrUpdate(item, policy);
		}
		public void AddOrUpdate(string key, object value, string regionName, CacheItemPolicy policy)
		{
			CacheItem item;

			item = new CacheItem()
			{
				Key = key,
				Value = value,
				RegionName = regionName,
			};
			AddOrUpdate(item, policy);
		}
		public void AddOrUpdate(string key, object value, string regionName, System.TimeSpan slidingExpiration)
		{
			CacheItemPolicy policy;

			policy = new CacheItemPolicy()
			{
				SlidingExpiration = slidingExpiration,
			};
			AddOrUpdate(key, value, regionName, policy);
		}
		public void AddOrUpdate(string key, object value, string regionName, System.DateTimeOffset absoluteExpiration)
		{
			CacheItemPolicy policy;

			policy = new CacheItemPolicy()
			{
				AbsoluteExpiration = absoluteExpiration,
			};
			AddOrUpdate(key, value, regionName, policy);
		}

		#endregion
		#region Contains

		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
		public bool Contains(string key, string regionName)
		{
			return this.Cache.Contains(key, regionName);
		}

		#endregion
		#region GetCacheItem

		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
		public CacheItem GetCacheItem(string key, string regionName)
		{
			return this.Cache.GetCacheItem(key, regionName);
		}

		#endregion
		#region GetCacheItemValue

		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
		public object GetCacheItemValue(string key, string regionName)
		{
			return this.Cache.GetCacheItemValue(key, regionName);
		}

		#endregion
		#region GetCount

		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
		public long GetCount(string regionName)
		{
			return this.Cache.GetCount(regionName);
		}

		#endregion
		#region Remove

		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
		public object Remove(string key, string regionName)
		{
			return this.Cache.Remove(key, regionName);
		}

		#endregion

		#region ToString

		public override string ToString()
		{
			return "CacheManager - ICache";
		}

		#endregion

		#endregion
		#region Constructors

		public CacheManager(Sidvall.Caching.ICache cache)
		{
			this.Cache = cache;
		}

		#endregion
	}
}
